package com.ruoyi.service.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.service.user.entity.UserEntity;
import com.ruoyi.service.user.query.LaborQuery;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 用户信息表 Mapper 接口
 * </p>
 *
 * @author Zane
 * @since 2025-09-27
 */
public interface UserMapper extends BaseMapper<UserEntity> {

  /**
   * <p>
   * 描述：根据用户名或者手机号查询用户信息
   * </p>
   *
   * @param userName 用户名
   * @param phone    手机号
   * @param userType 用户类型
   * @return 用户信息
   */
  @Select(
      "select user_id,user_name,phone,user_type from t_user where user_name=#{userName} and user_type=#{userType} and del_flag=0"
          + " union all "
          + "select user_id,user_name,phone,user_type from t_user where phone=#{phone} and user_type=#{userType} and del_flag=0")
  List<UserEntity> getByUserNameOrMobile(@Param("userName") String userName,
      @Param("phone") String phone, @Param("userType") String userType);

  @Select("<script> select u.* from t_user u"
      + " left join t_labor_ext l on u.user_id= l.user_id"
      + " where user_type='UL' and u.del_flag=0 and  u.status=1"
      + " <if test=\"laborQuery.name != null and laborQuery.name.trim() != ''\">"
      + " and u.name like concat('%',#{laborQuery.name},'%')"
      + " </if>"
      + " <if test=\"laborQuery.post != null and laborQuery.post != ''\">"
      + " and (l.post1 =#{laborQuery.post} or l.post2 =#{laborQuery.post} or l.post3 =#{laborQuery.post} )"
      + " </if>"
      + " </script>")
  List<UserEntity> listLaborByQuery(@Param("laborQuery") LaborQuery laborQuery);

  @Select("<script> select u.* from t_user u"
      + " left join t_labor_ext l on u.user_id= l.user_id"
      + " where user_type='UL' and u.del_flag=0 and   u.status=0"
      + " <if test=\"laborQuery.name != null and laborQuery.name.trim() !=''\">"
      + " and u.name like concat('%',#{laborQuery.name},'%')"
      + " </if>"
      + " <if test=\"laborQuery.post != null and laborQuery.post != ''\">"
      + " and (l.post1 =#{laborQuery.post} or l.post2 =#{laborQuery.post} or l.post3 =#{laborQuery.post} )"
      + " </if>"
      + " </script>")
  List<UserEntity> listUserNeedCheck(@Param("laborQuery") LaborQuery laborQuery);
}
